from django.db import models

# Create your models here.

class Lesson(models.Model):
  name = models.CharField(max_length=64)
  shortdescr = models.CharField(max_length=64)
  sname = models.CharField(max_length=64)
  def get_documents(self):
    return Document.objects.filter(lesson=self)
  def get_drills(self):
    return Drill.objects.filter(lesson=self).order_by('sname')
  def __str__(self):
    return self.sname	
'''
from drill.models import Lesson    
l = Lesson.objects.all()[0]   
'''

class Document(models.Model):
  name = models.CharField(max_length=64) # e.g. 'tutorial'
  sname = models.CharField(max_length=64)
  lesson = models.ForeignKey(Lesson)
  data = models.TextField()
  def __str__(self):
    return self.sname

class Drill(models.Model):
  name = models.CharField(max_length=64)
  sname = models.CharField(max_length=64)
  lesson = models.ForeignKey(Lesson)
  data = models.TextField()
  question_qty = models.IntegerField() 
  def __str__(self):
    return self.sname
  # how many questions will be asked before level is over, 
  # there could be more questions available though
  def total_qty(self):
    data = eval(self.data.replace('\r\n',''))
    return len(data)

class Evaluator(models.Model):
  # decides which grammatical backend is used to evaluate
  name = models.CharField(max_length=64)
  sname = models.CharField(max_length=64)
  def __str__(self):
    return self.sname

class Question(models.Model):
  verb = models.CharField(max_length=16)
  tense = models.CharField(max_length=16)
  grampers = models.CharField(max_length=2)
  question_text = models.TextField()
  evaluator = models.ForeignKey(Evaluator)
  drill = models.ForeignKey(Drill)

class ConjugationQuestion(models.Model):
  verb = models.CharField(max_length=16)
  tense = models.CharField(max_length=16)
  grampers = models.CharField(max_length=2)
  question_text = models.TextField()
  drill = models.ForeignKey(Drill)

class User(models.Model):
  username = models.CharField(max_length=16)
  full_name = models.CharField(max_length=64) 

class QuestionEvent(models.Model):
  question = models.ForeignKey(Question)
  time = models.DateField()
  user = models.ForeignKey(User)


#class Answer(models.Model):
#  ''' some questions will have several correct answers '''
  #text = models.TextField()
  #correctness = modelsIntegerField() # 1-5, 5 being most correct
  #expl = models.TextField() # explanation why this is not so correct if so



